package mytrain.kirayous.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import mytrain.kirayous.config.myAnnotationSwagger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.Map;


@Api(value = "学习",tags = {"标签","别名"},description = "已经过时的描述")//用于类上面，可以为控制器做别名，api文档上面会使用该别名
@RestController
@RequestMapping("/test")
public class testController {


    @GetMapping("/get")
    public String getString()
    {
        return "method get";
    }
    @myAnnotationSwagger//由这个修饰，不会生成api文档
    @PostMapping("/post")
    public Map<String, String> getPost(String username, String password)
    {
        Map<String,String> map=new HashMap<String,String>();
        map.put("username",username);
        map.put("password",password);
        return map;
    }
    @ApiOperation(value = "getPost1方法，此处用来测试@ApiOperation注解中的value值",notes = "此处用来测试@ApiOperation注解中的notes值")
    @PostMapping("/post1")
    public Map<String, String> getPost1(@ApiParam(value = "用于测试@ApiParam的value",name = "用户名",required = false,defaultValue = "admin") String username,
                                        @ApiParam(value = "用于测试@ApiParam的value",name = "password",required = false /* 此处设置为false，表明当前参数不一定要传值*/,defaultValue = "123456") String password)
    {
//        if (username==null) username="admin";
//        if (password==null) password="123456";
        Map<String,String> map=new HashMap<String,String>();
        map.put("username",username);
        map.put("password",password);
        return map;
    }
    @ApiIgnore//这个方法的使用就跟我们自定义那个注解的作用一样，都是忽略生成api文档
    @PostMapping("/ApiIgnore")
    public Map<String,String> testApiIgnore(String username,String password)
    {
        if (username==null) username="admin";
        if (password==null) password="123456";
        Map<String,String> map=new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        return map;
    }


/*    参数的一些具体描述 如果想使用多个，可以使用ApiImplicitParams*/
    @ApiImplicitParam(name = " @ApiImplicitParam-name",value = " @ApiImplicitParam-value",dataType = " @ApiImplicitParam-dataType",paramType = " @ApiImplicitParam-paramType")
    @PostMapping("/ApiImplicitParam")
    public Map<String,String> testApiImplicitParam(String username,String password)
    {
        if (username==null) username="admin";
        if (password==null) password="123456";
        Map<String,String> map=new HashMap<String,String>();
        map.put("username",username);
        map.put("password",password);
        return map;
    }



}
